﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TSCC.WinControl
{
    public partial class ControlMatrix : UserControl
    {

        [Category("TSCC")]
        [Description("該控制項是否允許在新增模式下輸入")]
        public bool AllowInsert
        {
            get;
            set;
        }

        [Category("TSCC")]
        [Description("該控制項是否允許在修改模式下輸入")]
        public bool AllowUpdate
        {
            get;
            set;
        }

        [Category("TSCC")]
        [Description("該控制項是否允許在查詢模式下輸入")]
        public bool AllowQuery
        {
            set;
            get;
        }

        /// <summary>
        /// 指定的控制項
        /// </summary>
        protected Control accessControl
        { 
            set
            {
                if (_accessControl == null)
                {
                    _accessControl = value;
                    SetFouckLeaveColor(Color.White);
                }                
            }
            get
            {
                return _accessControl;            
            }
        }

        protected Control _accessControl = null;

        public ControlMatrix()
        {
            InitializeComponent();
            
        }

        private void ControlMatrix_Enter(object sender, EventArgs e)
        {
            SetFouckLeaveColor(Color.Yellow);
        }

        private void ControlMatrix_Leave(object sender, EventArgs e)
        {
            SetFouckLeaveColor(Color.White);
        }

        protected void SetFouckLeaveColor(Color p_color)
        {
            if (accessControl != null)
            {
                accessControl.BackColor = p_color;
            }
            
        }

        public virtual void ClearText()
        {
            accessControl.Text = string.Empty;
        }

        /// <summary>
        /// 預設是字串格式!
        /// </summary>
        /// <param name="p_value"></param>
        public virtual void SetValue(object p_value)
        {
            //如果accessControl 不是Textbox 要變化嗎
            accessControl.Text = p_value.ToString();
        }

        protected override void Select(bool directed, bool forward)
        {
            //base.Select(directed, forward);
            accessControl.Focus();
        }
        
        
        
    }
}
